<?php
/* wwwschool project

Copyright (C) 2009  Phillip Aldridge
Email : info@imi21.com
Web site http://www.imi21.com

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/


/**
 *  File : list.php
 *  called only via ajax 
 *  
 *requires POST  
 */  

require '../../includes/classes/WS3tableview.php';
//require '../../includes/language/en.php';

$user_type=$_POST['type'];

$table=new WS3_TableView('main',400);
$table->setTitle( 'Listing '.$_mUSERS[ $user_type ] );
$table->addColumnTH('Name');
$table->addColumnTH('Firstname');
$table->addColumnTH('Email');
$table->addColumnActive(true,'user');
$table->addColumnView(true);
$table->addColumnEdit(true,'User');
$table->addColumnDelete(true,'User');

$table->addColumn('Address','editAddress');
$table->addColumn('Message','editMessage');

// list courses for teachers
if ($user_type =='3') $table->addColumn('Courses','listCoursesTeacher');
// list courses for students
if ($user_type =='4') $table->addColumn('Courses','listCoursesStudent');



$table->setAlternativeRows(true);
$table->setInfoRow(true);


$db=new WS3_Database();

// $$TODO security check on accessing levels
// $$TODO add different sorts
$q="SELECT * FROM `user` AS u WHERE u.user_type='$user_type' ORDER BY `last_name`";
 
if ($db->query($q))
{
  $count = $db->numberRows();
  while ( $db->nextRecord() )
  {
     $table->addRow($db->f('id'), array(
              'Name'=>javaSafeString( $db->f('last_name') ),
              'Firstname'=> javaSafeString( $db->f('first_name') ),
              'Email'=>$db->f('email'),
              'active'=>$db->f('active')
          ));
  } 
  $table->addToInfoRow("<p>Count = $count </p>");
  echo $table->display();
  $message="Listing";
}else{
  $message="Error : Empty list";
}



/** Get menu */
require '../../includes/menus/topUsers.php';
$menu=javaSafeString($menu);
echo "document.getElementById('topmenu').innerHTML='$menu';";

echo "document.getElementById('messages').innerHTML='$message';";

if (W3DEBUG) $debug=new WS3_Debug();

?>
